*=============================================================================================================
*
*	MASTER
*
*	runs all codes
*
*=============================================================================================================

*-------------------------------------------------------------------------------------------------------------
*SETTINGS
*-------------------------------------------------------------------------------------------------------------
* Select steps: "1 2" for main paper, "1 2 3" for main paper and appendix
global steps "1 2" // 3

* Display current working directory 
pwd

*Keep below code if current working directory is correct, otherwise delete "`c(pwd)'"  and put in the right working directory
cd "`c(pwd)'" 

* Packages	
foreach package in newey2 listtab ice lincomest carryforward tsspell randomtag hprescott shufflevar ivreg2 ranktest bgshade {
	capture which `package'
	if _rc==111 ssc install `package'
	}

clear
clear matrix
clear mata
set matsize 11000
set maxvar 32767
snapshot erase _all
set more off
pause on
set scheme s1color
graph set window fontface "Palatino"

*-------------------------------------------------------------------------------------------------------------



*___PREPARATION
// step 1: prepare data 
if strpos("$steps", "1") { 
	include "code/prepare_shock" // Figure 1; Table 1 (prepare shock variable)
	include "code/prepare" // (prepare all variables for analysis)
	}

	
	
*___IMPULSE RESPONSES
// step 2: local projections 
if strpos("$steps", "2") { 	
	include "Code/LP_agg" // Figures 2 and 4 (aggregated series results)

	include "Code/LP_disag_output" // Figure 3 (disaggregated outputs)
	include "Code/LP_disag_prices" // Figure 5 (disaggregated prices)
	include "Code/LP_disag_wages" // Figure 6 (disaggregated wages)

	}
	
	
	
*___APPENDIX
// step 3: appendix results
if strpos("$steps", "3") { 	
	clear
	include "Code/LP_subsets" // Figure A.1 (disaster subsets)
	include "Code/LP_longsalv" // Figure A.2 (protracted salvaging)
	include "Code/LP_1591" // Figure A.3 (1591 event)
	include "Code/LP_error" // Figure A.4 (measurement error)
	
	include "Code/LP_default" // Figure A.5; Table A.22 (sovereign default)
	include "Code/LP_sovereign" // Figure A.6 (sovereign risk spillover)
	include "Code/LP_outbound" // Figure A.7 (outbound disaster)
	
	include "Code/appendix_results" // Figures A.8, A.9, A.11; Table B.1 (lending rates and exports)
	
	include "Code/LP_rate_friction" // Figure A.10 (travel times)
	include "Code/LP_rate_nerrisk" // Figure A.12 (lending rate robustness)
	include "Code/volatilities" // (rate volatility comparison)
	
	include "Code/LP_disag_output_appendix" // Figure B.1 (additional disaggregated outputs)
	include "Code/LP_disag_prices_appendix" // Figure B.2 (additional disaggregated prices)
	
	include "Code/LP_disag_trade" // Figure B.3 (international trade)
	include "Code/LP_disag_debase" // Figure B.4 (currency debasement)
	include "Code/LP_nocc" // Figure B.5 (employment-unemployment flow check)

	include "Code/LP_salvage" // Figure B.6 (net losses excluding salvaging)
	include "Code/LP_pars" // Figure B.7 (parsimonious specification)
	include "Code/LP_noconflict" // Figure B.8 (no conflicts)
	include "Code/SE" // Figure B.9 (ARDL model)
	include "Code/LP_plus" // Figure B.10 (delayed shock)
	include "Code/LP_placebo" // Figure B.11 (Placebo test)
	include "Code/LP_pre1780" // Figure B.12 (pre-1780 sample)
	include "Code/LP_preevent" // Figure B.13 (pre-event analysis)
	
	include "Code/LP_allrates" // Figure B.14 (European interest rates)

	}

